const PipZip = require('pizzip')
const DocxTemplater = require('docxtemplater')
const Fs = require('node:fs')
const Path = require('node:path')
const content = Fs.readFileSync(Path.resolve(__dirname,'loops.docx'))
const zip = new PipZip(content)
const doc = new DocxTemplater(zip)
doc.render({
    "title": "Default title",
    "products": [
      {
        "title": "Duk",
        "name": "DukSoftware",
        "reference": "DS0"
      },
      {
        "title": "Tingerloo",
        "name": "Tingerlee",
        "reference": "T00"
      }
    ]
  })

const buf = doc.getZip().generate({
    type: "nodebuffer",
    // compression: DEFLATE adds a compression step.
    // For a 50MB output document, expect 500ms additional CPU time
    compression: "DEFLATE",
})
Fs.writeFileSync(Path.resolve(__dirname,'text.docx') ,buf)